#include "ConnectionFactory.h"
#include "api/create_peerconnection_factory.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "api/video_codecs/builtin_video_decoder_factory.h"
#include "api/video_codecs/builtin_video_encoder_factory.h"

rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> ConnectionFactory::m_factory = nullptr;

void ConnectionFactory::unInit()
{
    m_factory = nullptr;
}

rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> ConnectionFactory::get()
{
    if(m_factory == nullptr)
    {
        m_factory = webrtc::CreatePeerConnectionFactory(
                    nullptr /* network_thread */, nullptr /* worker_thread */,
                    nullptr /* signaling_thread */, nullptr /* default_adm */,
                    webrtc::CreateBuiltinAudioEncoderFactory(),
                    webrtc::CreateBuiltinAudioDecoderFactory(),
                    webrtc::CreateBuiltinVideoEncoderFactory(),
                    webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
                    nullptr /* audio_processing */);
    }

    return m_factory;
}
